package com.zang.blogz.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.SaTokenInfo;
import com.zang.blogz.model.input.ro.QQLoginRO;
import com.zang.blogz.model.output.UserInfoVO;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.UserAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 登录接口
 *
 * @author 臧臧 on 2022/6/17
 */
@RestController
@RequestMapping("/blogz/login")
@Api(tags = "管理员登录模块")
public class AdminLoginController {

    @Autowired
    private UserAuthService userAuthService;


    /**
     * 管理员登录接口
     * @param username 用户名
     * @param pwd 密码
     * @return
     */
    @PostMapping("/")
    public Result<UserInfoVO> adminLogin(@RequestParam("userName") String username,
                                         @RequestParam("passWord") String pwd) throws Exception {


        return userAuthService.login(username, pwd);
    }

    @SaCheckLogin
    @ApiOperation(value = "退出登录接口", notes = "退出登录接口")
    @DeleteMapping("/")
    public Result<String> adminOut() {

        return userAuthService.out();
    }

    @ApiOperation(value = "qq登录接口", notes = "qq登录接口")
    @PostMapping("/qqLogin")
    public Result<UserInfoVO> adminLogin(@RequestBody QQLoginRO qqLoginRO) {

        return userAuthService.qqLogin(qqLoginRO);
    }

    @ApiOperation(value = "gitee登录接口", notes = "gitee登录接口")
    @GetMapping("/giteeLogin")
    public Result<UserInfoVO> adminLogin(@RequestParam("code") String code) {

        return userAuthService.giteeLogin(code);
    }

}